<template>
	<view>
		<van-skeleton title avatar row="10" :loading="loading">
			<van-cell-group>
				<van-cell clickable size="large">
					<view slot="title">
						<van-row>
							<van-col span="6" offset="1">
								<open-data type="userAvatarUrl" />
							</van-col>
							<van-col span="16" offset="1">
								<open-data type="userNickName" lang="zh_CN" class="text" />
							</van-col>
						</van-row>
					</view>
				</van-cell>
			</van-cell-group>
			<van-cell-group v-show='!infoNull'>
				<van-field label="学校" :value="school" clickable readonly />
				<van-field label="学院" :value="college" clickable readonly />
				<van-field label="专业" :value="major" clickable readonly />
				<van-field label="年级" :value="grade" clickable readonly />
				<van-field label="班级" :value="banji" clickable readonly />
			</van-cell-group>
			<van-empty v-show='infoNull' description="您还未完善个人信息哦~">
				<van-button type="primary" round color="#006600" custom-class="completeBtn" @click="goToComplete">
					去填写</van-button>
			</van-empty>
			<div class="editBtn"  v-show='!infoNull'>
				<van-button type="primary" block round color="#006600" @click="goToComplete">
					去修改
				</van-button>
			</div>
		</van-skeleton>
		<van-notify id="van-notify" />
	</view>
</template>

<script>
	import Notify from '../../wxcomponents/vant/dist/notify/notify';
	export default {
		data() {
			return {
				infoNull: true,
				loading: true,
				school: "",
				college: "",
				major: "",
				grade: 1,
				banji: 1
			}
		},
		beforeCreate() {
			this.loading = true
		},
		mounted() {
			this.getUserInfo()
		},
		methods: {
			getUserInfo() {
				let self = this
				uni.request({
					url: getApp().globalData.baseURL + "/user/getUser",
					data: {
						"openid": wx.getStorageSync('openid')
					},
					header: {
						"token": wx.getStorageSync('token')
					},
					success: (res) => {
						if (res.data.code == -1) {
							self.infoNull = true
						} else {
							self.infoNull = false
							self.school = res.data.data.school
							self.college = res.data.data.college
							self.major = res.data.data.major
							self.grade = res.data.data.grade
							self.banji = res.data.data.banji
						}
						this.loading = false
					},
					fail: (err) => {
						this.loading = false
						Notify({
							type: 'danger',
							message: '获取用户信息失败'
						});
					}
				})
			},
			goToComplete(e) {
				uni.navigateTo({
					url: "../myInfo/myInfo"
				})
			}
		}
	}
</script>

<style scoped>
	.text {
		color: #808080;
		position: absolute;
		top: 50%;
		transform: translateY(-50%);
	}

	.editBtn {
		margin-top: 200rpx;
		text-align: center;
		margin-left: 100rpx;
		margin-right: 100rpx;
	}
</style>
